package com.sumi.erp.controller;

import com.sumi.common.annotation.Log;
import com.sumi.common.core.controller.BaseController;
import com.sumi.common.core.domain.AjaxResult;
import com.sumi.common.enums.BusinessType;
import com.sumi.common.utils.poi.ExcelUtil;
import com.sumi.erp.domain.BaseProductCategory;
import com.sumi.erp.service.IBaseProductCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品分类Controller
 * 
 * @author fgf67@163.com
 * @date 2024-06-20
 */
@RestController
@RequestMapping("/erp/category")
public class BaseProductCategoryController extends BaseController
{
    @Autowired
    private IBaseProductCategoryService baseProductCategoryService;

    /**
     * 查询商品分类列表
     */
    @PreAuthorize("@ss.hasPermi('erp:category:list')")
    @GetMapping("/list")
    public AjaxResult list(BaseProductCategory baseProductCategory)
    {
        List<BaseProductCategory> list = baseProductCategoryService.selectBaseProductCategoryList(baseProductCategory);
        return success(list);
    }

    /**
     * 导出商品分类列表
     */
    @PreAuthorize("@ss.hasPermi('erp:category:export')")
    @Log(title = "商品分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseProductCategory baseProductCategory)
    {
        List<BaseProductCategory> list = baseProductCategoryService.selectBaseProductCategoryList(baseProductCategory);
        ExcelUtil<BaseProductCategory> util = new ExcelUtil<BaseProductCategory>(BaseProductCategory.class);
        util.exportExcel(response, list, "商品分类数据");
    }

    /**
     * 获取商品分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('erp:category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(baseProductCategoryService.selectBaseProductCategoryById(id));
    }

    /**
     * 新增商品分类
     */
    @PreAuthorize("@ss.hasPermi('erp:category:add')")
    @Log(title = "商品分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseProductCategory baseProductCategory)
    {
        return toAjax(baseProductCategoryService.insertBaseProductCategory(baseProductCategory));
    }

    /**
     * 修改商品分类
     */
    @PreAuthorize("@ss.hasPermi('erp:category:edit')")
    @Log(title = "商品分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseProductCategory baseProductCategory)
    {
        return toAjax(baseProductCategoryService.updateBaseProductCategory(baseProductCategory));
    }

    /**
     * 删除商品分类
     */
    @PreAuthorize("@ss.hasPermi('erp:category:remove')")
    @Log(title = "商品分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseProductCategoryService.deleteBaseProductCategoryByIds(ids));
    }
}
